<script type="text/javascript">
  var visitPageCount = <?php echo sprintf('%d', $this->visits->count()); ?>;
  var visitPage = <?php echo sprintf('%d', $this->visits->getCurrentPageNumber()); ?>;
  var loadMorevisits = function() {
    visitPage++;
    new Request.HTML({
      'url' : en4.core.baseUrl + 'visits/whoiviewed-more',
      'data' : {
        'format' : 'html',
        'page' : visitPage
      },
      'onComplete' : function(responseTree, responseElements, responseHTML, responseJavaScript) {
        $('visits_loading_main').setStyle('display', 'none');
        if( '' != responseHTML.trim() && visitPageCount > visitPage ) {
          $('visits_viewmore').setStyle('display', '');
        }
        $('visits_main').innerHTML += responseHTML;
      }
    }).send();
  };
  en4.core.runonce.add(function(){
    if($('visits_viewmore_link')){
      $('visits_viewmore_link').addEvent('click', function() {
        $('visits_viewmore').setStyle('display', 'none');
        $('visits_loading_main').setStyle('display', '');
        loadMorevisits();
      });
    }

  });
</script>


<ul class='visits generic_list_widget' id="visits_main">
<?php if( $this->visits->getTotalItemCount() > 0 ): ?>
<?php foreach( $this->visits as $visit ): ?>
<?php $user = Engine_Api::_()->user()->getUser($visit->profile_id); ?>
<li>
    <div class="photo">
    <?php echo $this->htmlLink($user->getOwner()->getHref(), $this->itemPhoto($user->getOwner(), 'thumb.icon', $user->getOwner()->getTitle()), array('class' => 'thumb')) ?>
    </div>
    <div class="info">
        <div class="title">
        <?php echo $this->htmlLink($user->getHref(), $user->getTitle()) ?>
        </div>
        <div class="stats">
            <?php echo $this->translate('Last view');?>: <?php echo $this->timestamp($visit->visit_date) ?>
        </div>
        <div class="owner">
        <span><?php echo $this->translate(array('%s view', '%s views', $visit->visit_count), $this->locale()->toNumber($visit->visit_count)) ?></span>
        </div>
      </div>
</li>
<?php endforeach; ?>
<?php else: ?>
	<li style="background-color: transparent">
	<div class="tip">
      <span><?php echo $this->translate("You have not seen any profile.") ?></span>
   	</div>
	</li>
<?php endif; ?>
</ul>  
</div>
    <div style="clear:both;margin-top:15px;">
      <?php if( $this->visits->getTotalItemCount() > $this->visits->getItemCountPerPage() ): ?>
        <div class="visits_viewmore" id="visits_viewmore">
          <?php echo $this->htmlLink('javascript:void(0);', $this->translate('View More'), array(
            'id' => 'visits_viewmore_link',
            'class' => 'buttonlink icon_viewmore'
          )) ?>
        </div>
      <?php endif; ?>
      <div class="visits_viewmore" id="visits_loading_main" style="display: none;">
        <img src='application/modules/Core/externals/images/loading.gif' style='float:left; margin-right: 5px;' />
        <?php echo $this->translate("Loading ...") ?>
      </div>
    </div>